package lanou.giftsay_01.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import lanou.giftsay_01.R;
import lanou.giftsay_01.bean.SearchBean;
import lanou.giftsay_01.main.guidemain.SearchMainActivity;
import lanou.giftsay_01.main.guidemain.SearchOnItemClickListener;

/**
 * Created by dllo on 16/8/23.
 */
public class SearchRvAdapter  extends RecyclerView.Adapter<SearchRvAdapter.MySearchViewHolder>{
    Context context ;
    SearchBean searchBean ;
    SearchOnItemClickListener searchOnItemClickListener;

    public void setSearchOnItemClickListener(SearchOnItemClickListener searchOnItemClickListener) {
        this.searchOnItemClickListener = searchOnItemClickListener;
    }

    public SearchRvAdapter(Context context) {
        this.context = context;
        notifyDataSetChanged();
    }

    public void setSearchBean(SearchBean searchBean) {
        this.searchBean = searchBean;
    }

    @Override
    public MySearchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_search,parent,false);
        MySearchViewHolder mySearchViewHolder = new MySearchViewHolder(view);
        return mySearchViewHolder;
    }

    @Override
    public void onBindViewHolder(MySearchViewHolder holder, final int position) {
     holder.tv.setText(searchBean.getData().getHot_words().get(position));
     holder.tv.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
             searchOnItemClickListener.onClick(position ,searchBean);
         }
     });
    }

    @Override
    public int getItemCount() {
        return searchBean != null ? searchBean.getData().getHot_words().size():0;
    }

    public class MySearchViewHolder extends RecyclerView.ViewHolder {
        TextView tv ;
        public MySearchViewHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.tv_search_item);
        }
    }
}
